#ifndef DbPoolConfig_h__
#define DbPoolConfig_h__
#include <string>
#include "tinyxml/tinyxml.h"

#pragma pack( push, 1 )
#define TAG_DBPOOL					"DBPool"			
#define ATTR_DBPOOL_INITNUM	        "InitNum"	
#define ATTR_DBPOOL_MAXNUM	        "MaxNum"	
#define ATTR_DBPOOL_MINNUM	        "MinNum"		
#define ATTR_DBPOOL_MAXIDLE		    "MaxIdle"			
#define ATTR_DBPOOL_LOOPSPAN		"LoopSpan"			


typedef struct __DBPOOL_CFG
{
	unsigned int nInitNum;
	unsigned int nMaxNum;
	unsigned int nMinNum;
	unsigned int nMaxIdle;
	unsigned int nLoopPeriod;
}DBPOOL_CFG;

#pragma pack( pop )

class DBPoolConfigParser
{
public:
	static	bool XmlElement2DBPoolCfg( TiXmlElement* pDbInfo, DBPOOL_CFG& cfg )
	{
		if( NULL == pDbInfo )
			return false;

		const char*	tagName = pDbInfo->Value();

		if( ( tagName == NULL ) || _stricmp( tagName, TAG_DBPOOL ) )
			return false;

		int value(0);
		pDbInfo->Attribute(ATTR_DBPOOL_INITNUM, &value);
		cfg.nInitNum = value;

		pDbInfo->Attribute(ATTR_DBPOOL_MAXNUM, &value);
		cfg.nMaxNum = value;

		pDbInfo->Attribute(ATTR_DBPOOL_MINNUM, &value);
		cfg.nMinNum = value;

		pDbInfo->Attribute(ATTR_DBPOOL_MAXIDLE, &value);
		cfg.nMaxIdle = value;

		pDbInfo->Attribute(ATTR_DBPOOL_LOOPSPAN, &value);
		cfg.nLoopPeriod = value;

		return true;
	}

	static	bool	Xml2DBPoolCfg( const char* xmlString, DBPOOL_CFG& cfg )
	{
		TiXmlDocument	doc;
		doc.Parse( xmlString );
		TiXmlElement*	pRoot = doc.RootElement();
		return XmlElement2DBPoolCfg( pRoot, cfg );
	}
};

#endif	/*DbPoolConfig_h__*/
